cmake_minimum_required(VERSION 3.10.2)

###########################################################
#### Project configuration                             ####
###########################################################

project(MMMPlot)

###########################################################
#### Source configuration                              ####
###########################################################

set(SOURCE_FILES
    MMMPlot.cpp
    qcustomplot.cpp
    ../common/ApplicationBaseConfiguration.cpp
    MainWindow.cpp
    PlotWidget.cpp
    SinglePlotWidget.cpp
    ../common/HandleMotionsWithoutModel.cpp
)

set(HEADER_FILES
    MMMPlotConfiguration.h
    qcustomplot.h
    ../common/ApplicationBaseConfiguration.h
    MainWindow.h
    SensorPlot.h
    SensorPlotFactory.h
    PlotWidget.h
    SinglePlotWidget.h
    ../common/HandleMotionsWithoutModel.h
)

set(MOC_FILES
    qcustomplot.h
    MainWindow.h
    PlotWidget.h
    SinglePlotWidget.h
)

set(UI_FILES
    MainWindow.ui
    PlotWidget.ui
    SinglePlotWidget.ui
)

###########################################################
#### CMake package configuration                       ####
###########################################################

find_package(MMMCore REQUIRED)
set(EXTERNAL_LIBRARY_DIRS ${EXTERNAL_LIBRARY_DIRS} MMMCore KinematicSensor)

find_package(Simox REQUIRED)
set(EXTERNAL_LIBRARY_DIRS ${EXTERNAL_LIBRARY_DIRS} VirtualRobot)
set(EXTERNAL_LIBRARY_DIRS ${EXTERNAL_LIBRARY_DIRS} ${Simox_EXTERNAL_LIBRARIES})

set(EXTERNAL_LIBRARY_DIRS ${EXTERNAL_LIBRARY_DIRS} MMMSimoxTools)

find_package(Qt5PrintSupport REQUIRED)
set(EXTERNAL_LIBRARY_DIRS ${EXTERNAL_LIBRARY_DIRS} Qt5::PrintSupport)

###########################################################
#### Project build configuration                       ####
###########################################################

VirtualRobotQtApplication(${PROJECT_NAME} "${SOURCE_FILES}" "${HEADER_FILES}" "${MOC_FILES}" "${UI_FILES}")
target_link_libraries(${PROJECT_NAME} PRIVATE ${EXTERNAL_LIBRARY_DIRS} dl)

set(MMMPlot_BASE_DIR ${PROJECT_SOURCE_DIR} CACHE INTERNAL "")
add_definitions(-DMMMPlot_BASE_DIR="${MMMPlot_BASE_DIR}" -D_SCL_SECURE_NO_WARNINGS)

install(
    TARGETS ${PROJECT_NAME}
    EXPORT "${CMAKE_PROJECT_NAME}Targets"
    #LIBRARY DESTINATION lib
    #ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    #INCLUDES DESTINATION include
    COMPONENT bin
)

add_definitions(-DMMMTools_LIB_DIR="${MMMTools_LIB_DIR}")
add_definitions(-DMMMTools_SRC_DIR="${MMMTools_SOURCE_DIR}")
add_definitions(-DSENSOR_PLOT_PLUGIN_LIB_DIR="${SENSOR_PLOT_PLUGIN_LIB_DIR}")

###########################################################
#### Compiler configuration                            ####
###########################################################

include_directories(${EXTERNAL_INCLUDE_DIRS})
link_directories(${EXTERNAL_LIBRARY_DIRS})
add_definitions(${EXTERNAL_LIBRARY_FLAGS})

###########################################################
#### Sensor Plot Plugins                               ####
###########################################################

# Add sensor plot plugins
function(DefineSensorPlotPlugin SensorPlotPlugin_Name SensorPlotPlugin_Sources SensorPlotPlugin_Headers SensorPlugin_Name)
    add_library(${SensorPlotPlugin_Name} SHARED ${SensorPlotPlugin_Sources} ${SensorPlotPlugin_Headers})
    target_link_libraries(${SensorPlotPlugin_Name} PUBLIC ${EXTERNAL_LIBRARY_DIRS} ${SensorPlugin_Name})
    set_target_properties(${SensorPlotPlugin_Name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${SENSOR_PLOT_PLUGIN_LIB_DIR})

    install(
        TARGETS ${SensorPlotPlugin_Name}
        EXPORT "${CMAKE_PROJECT_NAME}Targets"
        LIBRARY DESTINATION lib/mmm_plugins/sensor_plot
        #ARCHIVE DESTINATION lib
        #RUNTIME DESTINATION bin
        #INCLUDES DESTINATION include
        COMPONENT lib
    )
    install(FILES ${SensorPlotPlugin_Headers} DESTINATION "include/MMM/${SensorPlotPlugin_Name}" COMPONENT dev)
endfunction()

add_subdirectory(SensorPlotPlugins)

###########################################################
#### Motion Handler Plugin                             ####
###########################################################

add_subdirectory(MotionHandlerPlugin)
